package com.xml.util;

import java.util.Date;

/**
 * 时间戳工具类
 *
 * @author xml E-Mail:kaioct@qq.com
 * @date 2021/3/8
 * @desc gridReportServerJava
 * @created 2021-03-08 11:14
 */
public class TimestampUtil {

    public static Long getCurrentTimestamp() {
        Date d = new Date();
        return getTimestamp(d);
    }

    /**
     * 获取精确到毫秒的时间戳
     *
     * @param date
     * @return
     **/
    public static Long getTimestamp(Date date) {
        if (null == date) {
            return (long) 0;
        }
        String timestamp = String.valueOf(date.getTime());
        return Long.valueOf(timestamp);
    }

    public static void main(String[] args) {
        Date d = new Date();
        System.out.println(getTimestamp(d));
        //结果：1504535566231
    }
}